//
//  PreViewController.m
//  DIYCoupon
//
//  Created by 张睿 on 16/12/30.
//  Copyright © 2016年 张睿. All rights reserved.
//

#import "PreViewController.h"
#import <Masonry.h>

#define SCREEN6P_SCALE ([UIScreen mainScreen].bounds.size.width /414)
#define PTSCALE ([UIScreen mainScreen].bounds.size.width /1080)

@interface PreViewController ()

@property (nonatomic, weak)UIImageView * preViewImage;
@property (nonatomic, weak)UIImageView * backgroundImage;
@property (nonatomic, weak)UILabel * bottomLabel;
@property (nonatomic, weak)UILabel *fontLabel;
@property (nonatomic, weak)UIImageView * markCardImage;

@end

@implementation PreViewController

- (void)setPreImage:(UIImage *)preImage{
    _preImage = preImage;
    
    self.preViewImage.image = preImage;
    
    [self setNeedsLayout];
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor blackColor];
        self.alpha = 0.99;
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI {
    
    UIImageView * backImage = [[UIImageView alloc] init];
    backImage.backgroundColor = [UIColor whiteColor];
    
    self.backgroundImage = backImage;
    
    [self addSubview:self.backgroundImage];
    
    UIImageView * preViewimage = [[UIImageView alloc] init];
    preViewimage.image = self.preImage;
//    preViewimage.image = [UIImage imageNamed:@"1.jpeg"];
    preViewimage.contentMode = UIViewContentModeScaleToFill;
    self.preViewImage = preViewimage;
    
    [self.backgroundImage addSubview:self.preViewImage];
    
    UILabel * bottomLabel = [[UILabel alloc] init];
    bottomLabel.textColor = [UIColor blackColor];
    bottomLabel.text = @"长按图片识别二维码获取优惠";
    
    self.bottomLabel = bottomLabel;
    
    [self.backgroundImage addSubview:bottomLabel];
    
    UILabel * fontLabel = [[UILabel alloc] init];
    fontLabel.textColor = [UIColor blackColor];
    fontLabel.text = @"锅德海鲜火锅(淮海西路点)";
    
    self.fontLabel = fontLabel;
    
    [self.backgroundImage addSubview:fontLabel];
    
    UIImageView * markCardImage = [[UIImageView alloc] init];
    markCardImage.image = [UIImage imageNamed:@"QRcode"];
    
    self.markCardImage = markCardImage;
    
    [self.backgroundImage addSubview:markCardImage];
}

#pragma mark - 页面布局 -
- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.backgroundImage mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(self).offset(50);
        make.centerX.mas_equalTo(self.mas_centerX);
//        make.leading.trailing.mas_equalTo(self);
//        make.height.mas_equalTo(self.preImage.size.height * 414 *SCREEN6P_SCALE / self.preImage.size.width + 70);
//        make.height.mas_equalTo((414 / self.preImage.size.width) * self.preImage.size.height + 60);
        make.height.mas_equalTo(self.preImage.size.height + 240 * PTSCALE);
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
    
    [self.preViewImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.mas_equalTo(self.backgroundImage);
        make.height.mas_equalTo(self.preImage.size.height);
    }];
    
    [self.fontLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.preViewImage.mas_bottom).offset(110 * PTSCALE);
        make.trailing.mas_equalTo(self.backgroundImage.mas_trailing).offset(-80);
        make.leading.mas_equalTo(self.backgroundImage).offset(25 * PTSCALE);
    }];
    
    [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.fontLabel.mas_bottom).offset(17 * PTSCALE);
//        make.leading.mas_equalTo(self.backgroundImage).offset(10);
        make.leading.mas_equalTo(self.fontLabel);
        make.trailing.mas_equalTo(self.fontLabel);
    }];
    
    [self.markCardImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.preViewImage.mas_bottom).offset(83 * PTSCALE);
        make.height.mas_equalTo(60 * SCREEN6P_SCALE);
        make.trailing.mas_equalTo(self.backgroundImage.mas_trailing).offset(-26 * PTSCALE);
        make.width.mas_equalTo(60 * SCREEN6P_SCALE);
    }];
}


@end
